import datetime
import os.path
import sys

from requests import options
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager


#创建一个驱动对象
class Driver:
    driver = ""
    #构造函数
    def __init__(self):
        options = webdriver.ChromeOptions()
        self.driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options = options)

    #创建屏幕截图的方法
    def getScreeShot(self):
        dirname = datetime.datetime.now().strftime('%Y-%m-%d')
        if not os.path.exists('../images/' + dirname):
            os.mkdir('../images/' + dirname)
        filename = sys._getframe().f_back.f_code.co_name + "-" + datetime.datetime.now().strftime('%Y-%m-%d-%H%M%S') + ".png"
        self.driver.save_screenshot("../images/"+dirname+"/"+filename)

ExamDriver = Driver()
